﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataBaseTable;

public partial class Manage_Ad_Lottery_Mode : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request.QueryString["id"]))
        {
            this.idhf.Value = Request.QueryString["id"];
            Submit.Click += new EventHandler(Update_Click);
            Submit.Text = "修改活动";
             this.initData();
        }
        else
        {

            Submit.Click += new EventHandler(Insert_Click);
            Submit.Text = "创建活动";
        }
    }
    private void initData()
    {
        LotteryTable lt = new LotteryTable(Convert.ToInt32(this.idhf.Value));
        LotteryName.Text = lt.LotteryName;
        LotteryDetail.Text=lt.LotteryDetail;
    }
    protected void Insert_Click(object sender, EventArgs e)
    {
        LotteryTable lt = new LotteryTable();
        lt.LotteryName = LotteryName.Text;
        lt.LotteryDetail = LotteryDetail.Text;
        try
        {
            lt.Insert();
            ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('创建抽奖活动成功');window.location.href='Ad_Lottery_List.aspx';</script>");
        }
        catch
        {
            ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('创建抽奖活动失败');</script>");
        }
    }
    protected void Update_Click(object sender, EventArgs e)
    {
        LotteryTable lt = new LotteryTable(Convert.ToInt32(this.idhf.Value));
        lt.LotteryName = LotteryName.Text;
        lt.LotteryDetail = LotteryDetail.Text;
        try
        {
            lt.Update();
            ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('更新抽奖活动成功');</script>");
        }
        catch
        {
            ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('更新抽奖活动失败');</script>");
        }
    }
}